package com.xwy.service.impl;

import com.xwy.dao.SysUserDao;
import com.xwy.entity.SysUser;
import com.xwy.service.UserService;
import com.xwy.util.UUIDUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Resource
    private SysUserDao sysUserDao;

    @Override
    public boolean addSysUser(SysUser sysuser) {
        sysuser.setUid(UUIDUtil.getUUID());
        boolean addSysUser = sysUserDao.addSysUser(sysuser);

        return addSysUser;
    }

    @Override
    public boolean updateSysUser(SysUser sysuser) {
        boolean updateSysUser = sysUserDao.updateSysUser(sysuser);
        return updateSysUser;
    }

    @Override
    public SysUser findSysUserByUno(String uno) {
        SysUser sysUser = new SysUser();
        sysUser.setUno(uno);
        return sysUserDao.findSysUserByUno(uno);

    }

    @Override
    public boolean findAuthByUserId(String uno, String uri) {
        List<String> authByUserId = sysUserDao.findAuthByUserId(uno);
        for (String s:authByUserId){
            int i = uri.indexOf(s);
            System.out.println(uri+"  "+s+"  "+i);
            if (i!=-1){
                System.out.println("鉴权成功");
                return true;
            }
        }
        System.out.println("鉴权失败");
        return false;
    }
}
